package com.mixsmart.bean;

import com.mixsmart.utils.StringUtils;

import java.util.Objects;

/**
 * @author 乌草坡
 * @since 2.5.0
 */
public class AbstractLabelValue<T> {

    private T value;

    private String label;

    public AbstractLabelValue() {
    }

    public AbstractLabelValue(T value, String label) {
        this.value = value;
        this.label = label;
    }

    public T getValue() {
        return value;
    }

    public void setValue(T value) {
        this.value = value;
    }

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    /**
     * 转换为数组
     * @return
     */
    public String[] toArray() {
        String[] array = new String[2];
        array[0] = StringUtils.handleNull(getValue());
        array[1] = getLabel();
        return array;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        LabelValue that = (LabelValue) o;
        return getValue().equals(that.getValue()) &&
                getLabel().equals(that.getLabel());
    }

    @Override
    public int hashCode() {
        return Objects.hash(getValue(), getLabel());
    }
}
